package com;

public class Main {

    public static boolean[] flag=new boolean[3];

    public static boolean judge(boolean[] f){
        for(int i=0;i<f.length;i++){
            if(!f[i]){
                return false;
            }
        }
        return true;
    }


    public static void main(String[] args){
        for(int i=0;i<flag.length;i++){
            flag[i]=false;
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    if (!flag[0]){
                        System.out.println("T1:work A");
                        flag[0]=true;
                    }
                    if (judge(flag)){
                        System.out.println("T1:work B");
                        break;
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    if (!flag[1]){
                        System.out.println("T2:work A");
                        flag[1]=true;
                    }
                    if (judge(flag)){
                        System.out.println("T2:work B");
                        break;
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    if (!flag[2]){
                        System.out.println("T3:work A");
                        flag[2]=true;
                    }
                    if (judge(flag)){
                        System.out.println("T3:work B");
                        break;
                    }
                }
            }
        }).start();
    }

}
